package com.huike.game.adapter;

import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.huike.game.ErrorHandle.RendInterfaceIsNull;
import com.huike.game.Rander.RenderInterface;

import java.util.List;
import java.util.Map;

public class Gv16Adpter <T>  extends BaseAdapter implements RenderInterface<T>{

    private List<T> data = null;
    private RenderInterface renderInterface=null;

    public Gv16Adpter(List<T> data){
        this.data = data;
    }

    public void setRenderInterface(RenderInterface renderInterface) {
        this.renderInterface = renderInterface;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View render = null;
        try {
            if(convertView == null){
                render = Render(position,parent,data);
                convertView.setTag(render);
            }else {
                render =(View) convertView.getTag();
            }

        } catch (RendInterfaceIsNull rendInterfaceIsNull) {
            rendInterfaceIsNull.printStackTrace();
        }
        return render;
    }

    @Override
    public View Render(int position, ViewGroup root, List<T> scope) throws RendInterfaceIsNull {
        if(this.renderInterface == null){
            throw new RendInterfaceIsNull("render interface is null");
        }

        return this.renderInterface.Render(position,root,scope);
    }
}
